//
//  LYDiscoverViewController.swift
//  WeChat
//
//  Created by mac on 2018/7/24.
//  Copyright © 2018年 RRC. All rights reserved.
//

import UIKit

class LYDiscoverViewController: UIViewController {
    let cellIdentifier:String = "reuseIdentifier"
    var listTableView:UITableView!
    fileprivate let itemDataSource:[[(name:String, iconImage:UIImage)]] = [
        [
            ("朋友圈", LYAsset.Ff_IconShowAlbum.image),
        ],
        [
            ("扫一扫", LYAsset.Ff_IconQRCode.image),
            ("摇一摇", LYAsset.Ff_IconShake.image),
        ],
        [
            ("附近的人", LYAsset.Ff_IconLocationService.image),
            ("漂流瓶", LYAsset.Ff_IconBottle.image),
        ],
        [
//            ("购物", LYAsset.Icon_bustime.image),
            ("游戏", LYAsset.MoreGame.image),
        ],
    ]
    
    override func viewDidLoad() {
        super.viewDidLoad()

        // Do any additional setup after loading the view.
        
        self.title = "发现"
        self.view.backgroundColor = UIColor.viewBackgroundColor
        
        listTableView = UITableView()
        listTableView.backgroundColor = UIColor.init(ts_hexString: "#EFEFF4")
        listTableView.delegate = self
        listTableView.dataSource = self
        self.view.addSubview(listTableView)
        listTableView.snp.makeConstraints { (make) in
            make.edges.equalTo(0)
        }
        listTableView.estimatedRowHeight = 44
        listTableView.estimatedSectionFooterHeight = 0
        listTableView.estimatedSectionHeaderHeight = 0
        listTableView.tableFooterView = UIView()
//        listTableView.register(TSImageTextTableViewCell.self, forCellReuseIdentifier: cellIdentifier)
        
    }

    override func didReceiveMemoryWarning() {
        super.didReceiveMemoryWarning()
        // Dispose of any resources that can be recreated.
    }
    

    /*
    // MARK: - Navigation

    // In a storyboard-based application, you will often want to do a little preparation before navigation
    override func prepare(for segue: UIStoryboardSegue, sender: Any?) {
        // Get the new view controller using segue.destinationViewController.
        // Pass the selected object to the new view controller.
    }
    */

}

// MARK: UITableViewDelegate
extension LYDiscoverViewController:UITableViewDelegate {
    func tableView(_ tableView: UITableView, estimatedHeightForHeaderInSection section: Int) -> CGFloat {
        if section == 0 {
            return 15
        }else{
            return 20
        }
    }
    
//    func tableView(_ tableView: UITableView, estimatedHeightForFooterInSection section: Int) -> CGFloat {
//        return 0.0000001
//    }
    
    func tableView(_ tableView: UITableView, heightForRowAt indexPath: IndexPath) -> CGFloat {
        return listTableView.estimatedRowHeight
    }
    
    func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) {
        
    }
    
}

// MARK: UITableViewDataSource
extension LYDiscoverViewController:UITableViewDataSource {
    func numberOfSections(in tableView: UITableView) -> Int {
        return itemDataSource.count
    }
    
    func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
        let rows = itemDataSource[section]
        return rows.count
    }
    
    func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
        var cell = tableView.dequeueReusableCell(withIdentifier: cellIdentifier ) as? TSImageTextTableViewCell
        if cell == nil {
            cell = TSImageTextTableViewCell(style: .default, reuseIdentifier: cellIdentifier)
        }
        let item = itemDataSource[indexPath.section][indexPath.row]
        cell?.iconImageView.image = item.iconImage
        cell?.titleLabel.text = item.name
        return cell!
    }
    
    
}
